package com.xxx.common.core.sampleframe.service.impl;

import com.xxx.common.core.sampleframe.dao.FastDao;
import com.xxx.common.core.sampleframe.search.Search;
import com.xxx.common.core.sampleframe.service.FastService;
import com.xxx.common.core.sampleframe.springside.Collections3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import javax.sql.DataSource;
import java.util.List;


public  class FastServiceImpl<T > implements FastService<T> {
	
	protected FastDao baseDao;
	@Autowired
	private DataSource ds;

	@Override
	public void update(T t) {
		baseDao.update(t);
	}

	@Override
	public void insert(T t) {
		baseDao.insert(t);
	}

	@Override
	public void delete(T t) {
		baseDao.delete(t);
	}

	@Override
	public List<T> find(Search search) {
		try {
			return baseDao.find(search);
		}catch (Exception e){
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Page<T> findPage(Search search) {
		try {
			return baseDao.findPage(search);
		} catch (Exception e) {
			e.printStackTrace();
		}
		 return null;
	}

	@Override
	public T findOne(Search search) {
		List<T> result =  find(search);
		if(Collections3.isEmpty(result)){
			return null;
		}
		return result.get(0);
	}

	@Override
	public Long count(Search search) {
		return baseDao.count(search);
	}

	@Override
	public T findById(Long id) {
		return findOne(new Search().addSearchFilter("EQ_id",id));
	}

	@Override
	public List<T> findPageWithoutCount(Search search) {
		return baseDao.findPageWithoutCount(search);
	}


}
